package com.jsj.subway.ai.demo.controller;

import com.jsj.subway.ai.common.R;
import com.jsj.subway.ai.demo.dto.ChatDTO;
import com.jsj.subway.ai.demo.service.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Deque;

@RestController
@Slf4j
@RequestMapping("/api")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @RequestMapping(value = "/connect/sse",method  = {RequestMethod.GET})
    public SseEmitter connectSSE(HttpServletResponse response){

        return demoService.connect(response);
    }


    //开始会话 set 0 1 2
    @RequestMapping(path = "/begin/{Key}",method = {RequestMethod.POST,RequestMethod.GET})
    public R<String> begin(@PathVariable("Key") Integer key){
        return R.ok(demoService.begin(key));
    }

    @RequestMapping(path = "/getMessageRecord/{Key}",method = {RequestMethod.POST,RequestMethod.GET})
    public R<Deque<ChatDTO.MessageRecord>> getMessageRecord(@PathVariable("Key") Long key){
        return R.ok(demoService.getMessageRecord(key));
    }




    //会话接口 调用Agent
    @RequestMapping(path = "/chat",method = RequestMethod.POST)
    public R<ChatDTO.MessageRecord> chat(@RequestBody ChatDTO.MessageRequest messageRequest){
        return R.ok(demoService.sessionChatByStream(messageRequest));
    }


    @RequestMapping(path = "/test",method = RequestMethod.POST)
    public R<ChatDTO.MessageRecord> test(@RequestBody ChatDTO.MessageRequest messageRequest){
        return R.ok(demoService.sessionChat(messageRequest));
    }

    @RequestMapping(path = "/getUrlByContent",method = RequestMethod.POST)
    public R<String> getUrlByContent(String content){
        return R.ok(demoService.getUrlByContent(content));
    }


}
